home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / CC_C / 0574.ZIP / OPEN.ASM < prev    next >
Assembly Source File  |  1986-08-30  |  841b  |  49 lines

  1. include compiler.inc
  2.  
  3.     ttl    OPEN, 1.04, 08-30-86, clr
  4.  
  5. ;low-level handle opener (was _opn() in prev versions)
  6.  
  7.     dseg
  8.     exterr
  9.  
  10.     cseg
  11.     procdef open, <<path, ptr>, <mode, byte>>
  12.     pushds
  13.  
  14.     xor    ax,ax
  15.     moverr    ax
  16.     ldptr    dx,path,ds        ;name pointer
  17.     mov    al,mode            ;mode value
  18.     inc    al            ;to simplify testing
  19.     and    al,3            ;take it mod 3
  20.     jz    err            ; 0 not valid
  21.     test    al,1            ;read or append?
  22.     jz    cre            ;no, must be write only
  23.     dec    al            ;to DOS mode code
  24.     mov    ah,3dh            ;let DOS open it
  25.     int    21h
  26.     jnb    ex2            ;opened OK
  27.     cmp    ax,2            ;file not found?
  28.     jnz    err            ;no, real error
  29.     mov    bl,mode            ;yes, check for W
  30.     test    bl,2
  31.     jz    err            ;nope, real error
  32.  
  33. cre:
  34.     xor    cx,cx            ;no attributes
  35.     mov    ax,3C00h        ;on new file
  36.     int    21h
  37.     jnb    ex2            ;created OK
  38.  
  39. err:
  40.     moverr    ax        ;error
  41.     mov    ax,-1
  42.  
  43. ex2:
  44.     pret
  45.  
  46.     pend    open
  47.  
  48.     finish
  49.